package com.applet.config;

import com.applet.interceptor.GlobalInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * spring mvc配置类
 */
@Slf4j
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {


    /**
     * 添加静态资源映射 html、css、js等前端代码的映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("springmvc 静态资源映射......");
        registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources");
        registry.addResourceHandler("/webjars/**").addResourceLocations("class[ath:/META-INF/resources/webjars/");
    }




    //拦截器bean
    @Resource
    private GlobalInterceptor globalInterceptor;

    //拦截器配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("springmvc 全局拦截器配置......");
        registry.addInterceptor(globalInterceptor).addPathPatterns("/**");
    }




}
